// 工具管理接口
import request from '@/utils/request'
import type { ToolResData,queryParams } from './toolType'

enum API {
  all_tool = '/api/expand-learning/category/page',
  add_tool = '/api/expand-learning/category/add',
  update_tool = '/api/expand-learning/category/update',
  delete_tool = '/api/expand-learning/category/delete',
}
// 获取工具列表
export const reqAllTool = (params: queryParams) => {
  const queryParams = new URLSearchParams({
    current: params.current.toString(),
    size: params.size.toString(),
    categoryName: params.categoryName || ''
  }).toString()
  const url = `${API.all_tool}?${queryParams}`
  return request.get<any, ToolResData>(url)
}
// 新增工具、编辑工具
export const reqAddOrUpdateTool = (data: any) => {
  let hasId = data.has('id')
  let idValue = hasId ? data.get('id') : null
  let hasValue = idValue !== null && idValue !== ''
  if (hasValue) {
    return request.put<any,any>(API.update_tool, data)
  } else {
    return request.post<any,any>(API.add_tool, data)
  }
}
// 删除单个工具
export const reqRemoveTool = (id: number, version:number) => {
  return request.delete<any,any>(API.delete_tool + `?id=${id}&version=${version}`)
}

